#include "board_base.h"

#include "bsp_uart.h"
//#include "SEGGER_RTT.h"
//#include "ITM.h"
#include "tim.h"
#include "gpio.h"
#include "task_main.h"
//#include "log.h"
//#include "w25qxx.h"
/*-----------------------------------------------------------------------
|                                define                                 |
-----------------------------------------------------------------------*/
//#define BOARDTAG "Board"
//#define Board_Firmware_ProjectName "STM32F030C8T6_Ammeter_Project"
//#define Board_Firmware_Version  STR(1.0)
//#define Board_Firmware_Auther  "liuzhihua"
//#define Board_System_Frequnce   SystemCoreClock
//const char LINESTR[] = "--------------------------------------------------------------------------------\n";
//#define STR(str) #str


/*-----------------------------------------------------------------------
|                               Function                                |
-----------------------------------------------------------------------*/

/**
 * @brief 记录归零，开始测量时间
 * @param timecnt 用来记录时间的变量
 * @retval uint32_t 
 */
void bsp_MesureTimeStart(uint32_t *timecnt)
{
	*timecnt = HAL_GetTick();
}

/**
 * @brief 测量时间
 * @param old_counter 用来记录时间的变量
 * @retval uint32_t 上次使用到这次使用的时间(ms)
 */
uint32_t bsp_MesureTime(uint32_t *old_counter)
{
	uint32_t counter, couter_current;
	couter_current = HAL_GetTick();
	if (couter_current > *old_counter)//没有溢出
		counter = couter_current - *old_counter;
	else//发生过溢出
		counter = couter_current + 0XFFFFFFFF - *old_counter;
	*old_counter = couter_current;
	return (counter);
}


// void board_info_output(void)
// {
// 	LOGS("JLink RTT Start\n");
// 	LOGS(LINESTR);
// 	LOG_INFO(BOARDTAG, "ProjectName :  %s\n",Board_Firmware_ProjectName);
// 	LOG_INFO(BOARDTAG, "Version     :  %s\n",Board_Firmware_Version);
// 	LOG_INFO(BOARDTAG, "Auther      :  %s\n",Board_Firmware_Auther);
// 	LOG_INFO(BOARDTAG, "SystemClock :  %d\n",Board_System_Frequnce);
// 	LOG_INFO(BOARDTAG, "Extern Flash: W25Q%d[ID:%d|FlashSize:%dKB]\n",w25qxx.BlockCount/2, w25qxx.ID, w25qxx.BlockCount * (w25qxx.BlockSize/1024));
// 	LOGS(LINESTR);
// }


/**
 * @brief 板载资源初始化
 */
void board_base_init(void)
{
	// HAL_TIM_Base_Start(&htim5);
	// HAL_TIM_Base_Start(&htim2);
	HAL_TIM_Base_Start_IT(&htim17);//PB0,PB1
	UART_BSP_Init();
//	LogSetLevel(LOG_LEVEL_NONE);
// 	board_info_output();
}

/**
  * @brief  Period elapsed callback in non-blocking mode
  * @param  htim TIM handle
  * @retval None
  */
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
	if (htim == &htim17)
	{
		TaskInput((const void*)1);	
		TaskOutput((void*)1);
	}

}

/**
  * @brief  EXTI line detection callbacks.
  * @param  GPIO_Pin: Specifies the pins connected EXTI line
  * @retval None
  */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{


}

